<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<title>发布频道</title>
<%@include file="../include/commonFile.jsp" %>
<link rel="stylesheet" href="${ctx}/css/ui/activity/publish_act.css">
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
	<%@include file="../include/sidebar.jsp"%>
	<!--内容-->
	<section>
		<div class="section-main">
			<!-- 正文请写在这里 -->
			<div class="add-form-content">
			<form id="myForm" class="layui-form" method="post" action="${ctx}/channel/channel/save.do">
				<input type="hidden" name="applyId" value="${applyId}">
				<input type="hidden" name="subjectId" value="${subjectId}">
				<div class="layui-form-item">
					<label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="name" lay-verify="name" style="width: 85%" autocomplete="off" placeholder="分类名称" class="layui-input" value="${channel.name}">
						<input type="hidden" name="id" value="${channel.id}"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">封面图<span class="f-verify-red">*</span></label>
					<div class="cover-content">
						<input type="hidden" name="picture" id="pic" lay-verify="pic" value="${channel.picture}" />
						<c:if test="${channel == null || empty channel.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${channel != null && not empty channel.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url('${channel.picture}')"></span>
						</c:if>
						<a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加封面图</a>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">描述<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
				   		<textarea name="remarks" placeholder="分类描述" lay-verify="remarks" class="layui-textarea" style="width: 85%" >${channel.remarks}</textarea>
				    </div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
				   		<a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
				  	</div>
				</div>
			</form>
			</div>
		</div><!--底部-->
		<%@include file="../include/footer.jsp" %>
	</section>
</div>
<script>
	$(function() {

        layui.use(['form'], function () {
            var form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                name : function(value) {
                    if (value == "") {
                        return '请填写频道名称';
                    }
                },
                pic : function(value) {
                    if (value == "") {
                        return "请上传频道封面图";
                    }
                },
                remarks : function(value) {
                    if (value == "") {
                        return '请填写频道描述';
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            if (util.isValid('${applyId}')) {
                                util.layerMsgSuccess("提交成功", function () {
                                    location.href = "${ctx}/subject/apply/applyList.do?subjectId=" + '${subjectId}' + "&applyId=" +'${applyId}';
                                });
							} else {
                                util.layerMsgSuccess("提交成功", function () {
                                    location.href = "${ctx}/channel/channel/publishList.do";
                                });
							}
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    });
                });
                return false;
            });
            form.render('radio');
        });

        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.CHANNEL.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
	})
</script>
</body>
</html>